//
//  MyInformationViewController.swift
//  ezyform
//
//  Created by MoennigQ on 19/02/2017.
//  Copyright © 2017 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import MBProgressHUD
class MyInformationViewController: ModelBaseViewController {

    let customView = MyInformationView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view = customView
        self.customView.setTitle(R.string.localizable.profile())
        
        self.customView.closeBtn.addTarget(self, action: #selector(dismissVC), for: UIControl.Event.touchUpInside)
        self.loadData()
        // Do any additional setup after loading the view.
    }
    func loadData(){
        //set block
        let vm = MyInformationService()
        vm.setBlockAfterNetwork({(result , _) -> Void in
            ModelViewUtil.shared.hideLoadingView()
            
            guard let tempModel = result as? MyInformationModel else{
                return
            }
            self.initViewModels(tempModel)
            
        }) { (code, error) -> Void in
            ModelViewUtil.shared.hideLoadingView()
            Tool().showErrorInfo(code, error)
        }
        //add Loading view
        ModelViewUtil.shared.showLoadingView()
        vm.getMyInformation()

    }
    private func initViewModels(_ model: MyInformationModel){
        var list = [ProfileViewModel]()
        list.append(ProfileViewModel(imageName: "me_myinformation_name",title: "Name",content: model.name,seperateHeight: 8))
        list.append(ProfileViewModel(imageName: "me_myinformation_email",title: "Email",content: model.email))
        list.append(ProfileViewModel(imageName: "me_myinformation_phone",title: "Phone",content: model.phone ,hideLineViewFlag: true))
        
        /// 2024-03-02 add
        list.append(ProfileViewModel(imageName: "me_myinformation_accreditatonnumber",title: "SAA Number",content: model.saa_number ,seperateHeight: 34))
        list.append(ProfileViewModel(imageName: "me_myinformation_electricalnumber",title: "Licensed Electrical Number",content: model.electrician_licenses ))
        list.append(ProfileViewModel(imageName: "me_myinformation_expriydate",title: "Effective Date",content: model.effective_date ))
        list.append(ProfileViewModel(imageName: "me_myinformation_expriydate",title: "Expiry Date",content: model.expiry_date ))
            
        list.append(ProfileViewModel(imageName: "me_myinformation_status",title: "Status",content: model.status ))
//        list.append(ProfileViewModel(imageName: "me_myinformation_status",title: "Status",content: model.status ,seperateHeight: 34))
        if XpTools.isGreaterThanOverTime() == false {
            list.append(ProfileViewModel(imageName: "me_myinformation_accreditatonnumber",title: "Accreditation Number",content: model.accredited_number ))
        }
        
        //转换时间格式
//        let formatResult = DateUtil().convertDateStrToDateStr(dateStr: model.accredited_number_end_date , oldFormat: "yyyy-MM-dd", newFormat: "dd/MM/yyyy")
//        list.append(ProfileViewModel(imageName: "me_myinformation_expriydate",title: "Expiry Date",content: formatResult ,hideLineViewFlag: true))
        list.append(ProfileViewModel(imageName: "me_myinformation_address",title: "Address",content: model.address ,seperateHeight: 34))
        self.customView.list = list
        self.customView.tableView.reloadData()
    }
}
